﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
using Helpers;


namespace Function
{
    public class PRFunction
    {
        static string conStrSim = INIFileHelper.ReadIniValue("DB", "CONNECTIONSTRING_Simulation", Application.StartupPath + @"\Setting.ini").Trim();
        static string conStrAgv = SystemParamsHelper.DBConnectionString = INIFileHelper.ReadIniValue("DB", "CONNECTIONSTRING", Application.StartupPath + @"\Setting.ini").Trim();
        public PRFunction()
        {
        }

        public static void GetDBConnectionString(string connstring)
        {
            SQLServerDBController._defultConnectionString = connstring;//获取数据库连接参数            
        }
        public static int UPDATE_SQL(string sql, params SqlParameter[] ps)
        {
            string conStr = conStrAgv;
            int rows;
            try
            {
                using (SqlConnection con = new SqlConnection(conStr))
                {
                    SqlCommand comm = new SqlCommand(sql, con);
                    comm.Parameters.AddRange(ps);
                    con.Open();
                    rows = comm.ExecuteNonQuery();
                }
            }
            catch 
            {
                rows = -1;
            }
            return rows;
        }

        /// <summary>
        /// 查询语句
        /// </summary>
        /// <param name="sql">sql语法</param>
        /// <returns></returns>
        public static DataTable SELECT_SQL(string sql)
        {
            DataSet ds = new DataSet();
             
                string conStr = conStrAgv;
                using (SqlDataAdapter sda = new SqlDataAdapter(sql, conStr))
                {
                    sda.Fill(ds);
                }
             
            return ds.Tables[0];
        }

        public static DataTable SELECT_SQL_MAP(string sql)
        {
            DataSet ds = new DataSet();
             
                string conStr = conStrSim;
                using (SqlDataAdapter sda = new SqlDataAdapter(sql, conStr))
                {
                    sda.Fill(ds);
                }
             
            return ds.Tables[0];
        }
        //Map Elevator point
        public static int INSERT_MapInfo_Elevator()
        {
            SqlCommand comm = new SqlCommand("[PR_INSERT_MapInfo_Elevator]");
            comm.CommandType = CommandType.StoredProcedure;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        //public static int PR_Insert_TaskInfoInit_AndType(string TaskHandleAGV, string TaskContent, string TaskState, string TaskType)
        //{
        //    SqlCommand comm = new SqlCommand("[PR_Insert_TaskInfoInit_AndType]");
        //    comm.CommandType = CommandType.StoredProcedure;
        //    comm.Parameters.Add("@TaskHandleAGV", SqlDbType.VarChar, 50).Value = TaskHandleAGV;
        //    comm.Parameters.Add("@TaskContent", SqlDbType.VarChar, 500).Value = TaskContent;
        //    comm.Parameters.Add("@TaskState", SqlDbType.VarChar, 50).Value = TaskState;
        //    comm.Parameters.Add("@TaskType", SqlDbType.VarChar, 50).Value = TaskType;
        //    int i = -1;
        //    try
        //    {
        //        i = SQLServerDBController.ExecuteNonQuery(comm);
        //    }
        //    catch (Exception)
        //    {
        //        i = -1;
        //    }
        //    return i;
        //}

        public static int PR_Insert_CXCallInfo(string CX_CXNO)
        {
            SqlCommand comm = new SqlCommand("[PR_Insert_CXCallInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CX_CXNO", SqlDbType.VarChar, 50).Value = CX_CXNO;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }



        //-------------------------
        public static DataTable Select_UserForLogin(string UserName, string UserPassword, string UserType)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_UserForLogin]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value = UserName;
            comm.Parameters.Add("@UserPassword", SqlDbType.VarChar, 50).Value = UserPassword;
            comm.Parameters.Add("@UserType", SqlDbType.VarChar, 50).Value = UserType;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch  
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_AGVInfo()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_AGVInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }

        public static DataTable Select_NodeInfo()
        {
            SqlCommand comm = new SqlCommand("[Select_NodeInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }

        public static DataTable Select_Plc()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_PLCState]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }
        public static DataTable Select_PLCInfo()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_PLCInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }

        public static DataTable Select_AGVInfo_NoCharger()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_AGVInfo_NoCharger]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }


        public static DataTable Select_AGVInfo_ByRemark(string AGV_Remark)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_AGVInfo_ByRemark]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_Remark", SqlDbType.VarChar, 50).Value = AGV_Remark;

            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }

        public static DataTable Select_ChargerInfo()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_ChargerInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }

        public static DataTable Select_ChargerInfo_ByAGVRemark(string AGVRemark)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_ChargerInfo_ByAGVRemark]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVRemark", SqlDbType.VarChar, 50).Value = AGVRemark;

            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }
        public static DataTable Select_ChargerInfo_ByCharger_Location(string Location)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_ChargerInfo_ByCharger_Location]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Charger_Location", SqlDbType.VarChar, 50).Value = Location;

            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }

        public static DataTable Select_PLCState_ByName(string PLCName)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_PLCState_ByName]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@PLCName ", SqlDbType.VarChar, 50).Value = PLCName;

            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }
        public static DataTable Select_ErrorInfo()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_ErrorInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }

        public static int Update_AGVInfo(string AGV_IP, string AGV_Location, string AGV_Voltage, int AGV_ErrorCode, int AGV_WarnCode, int AGV_Obstruction,
            int AGV_Speed, int AGV_Direction, string AGV_Route, string TaskNO, int AGV_ChargerState, string AGV_IsLock)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AGVInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@AGV_Location", SqlDbType.VarChar, 50).Value = AGV_Location;
            comm.Parameters.Add("@AGV_Voltage", SqlDbType.VarChar, 50).Value = AGV_Voltage;
            comm.Parameters.Add("@AGV_ErrorCode", SqlDbType.Int, 10).Value = AGV_ErrorCode;
            comm.Parameters.Add("@AGV_WarnCode", SqlDbType.Int, 10).Value = AGV_WarnCode;
            comm.Parameters.Add("@AGV_Obstruction", SqlDbType.Int, 10).Value = AGV_Obstruction;
            comm.Parameters.Add("@AGV_Speed", SqlDbType.Int, 10).Value = AGV_Speed;
            comm.Parameters.Add("@AGV_Direction", SqlDbType.Int, 10).Value = AGV_Direction;
            comm.Parameters.Add("@AGV_Route", SqlDbType.VarChar, 8000).Value = AGV_Route;
            comm.Parameters.Add("@AGV_Task", SqlDbType.VarChar, 50).Value = TaskNO;
            comm.Parameters.Add("@AGV_ChargerState", SqlDbType.Int, 10).Value = AGV_ChargerState;
            comm.Parameters.Add("@AGV_IsLock", SqlDbType.VarChar, 50).Value = AGV_IsLock;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_AGVInfo_Network(string AGV_IP, int AGV_Network)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AGVInfo_Network]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@AGV_Network", SqlDbType.Int, 10).Value = AGV_Network;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static int Update_AGVInfo_TaskNo(string AGV_IP, string TaskNo)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AGVInfo_TaskNo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVIP", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@TaskNo", SqlDbType.VarChar, 50).Value = TaskNo;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int PR_Update_AGVStop_AutoDoor(string AGV_IP, string AGVStop_AutoDoor)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AGVStop_AutoDoor]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVIP", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@AGVStop_AutoDoor", SqlDbType.VarChar, 50).Value = AGVStop_AutoDoor;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_AGVInfo_TaskFlag(string AGV_IP, string TaskFlag)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AGVInfo_TaskFlag]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVIP", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@TaskFlag", SqlDbType.VarChar, 50).Value = TaskFlag;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int PR_Update_AGVInfo_AGV_Reserve1(string AGV_IP, string Reserve1)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AGVInfo_AGV_Reserve1]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVIP", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@AGV_Reserve1", SqlDbType.VarChar, 50).Value = Reserve1;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_AGVElevatorNo(string AGV_IP, int AGV_ElevatorNo)
        {
            SqlCommand comm = new SqlCommand("[Update_AGVElevatorNo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVIP", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@AGV_ElevatorNo", SqlDbType.Int, 10).Value = AGV_ElevatorNo;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static int Update_AGVILevel(string AGV_IP, string level)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AGVLevel]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@AGV_Level", SqlDbType.VarChar, 50).Value = level;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int PR_Update_AGV_LastAutoDoor(string AGV_IP, string AGV_LastAutoDoor)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AGV_LastAutoDoor]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@AGV_LastAutoDoor", SqlDbType.VarChar, 50).Value = AGV_LastAutoDoor;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_AGVInfo_Route(string AGV_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AGVInfo_Route]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_AGVInfo_Using(string AGV_IP, int AGV_UsingState)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AGVInfo_Using]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@AGV_UsingState", SqlDbType.Int, 10).Value = AGV_UsingState;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static int Update_PLC_State(string PLCIP, int State)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_PLC_State]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@PLCIP", SqlDbType.VarChar, 50).Value = PLCIP;
            comm.Parameters.Add("@State", SqlDbType.Int, 10).Value = State;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static int Update_ChargerInfo_Network(string Charger_IP, int Charger_Network)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_ChargerInfo_Network]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Charger_IP", SqlDbType.VarChar, 50).Value = Charger_IP;
            comm.Parameters.Add("@Charger_Network", SqlDbType.Int, 10).Value = Charger_Network;


            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_ChargerInfo(string Charger_IP, int Charger_InOut)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_ChargerInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Charger_IP", SqlDbType.VarChar, 50).Value = Charger_IP;
            comm.Parameters.Add("@Charger_InOut", SqlDbType.Int, 10).Value = Charger_InOut;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_AllEquipment_Network(int AGV, int Charger)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AllEquipment_Network]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV", SqlDbType.Int, 10).Value = AGV;
            comm.Parameters.Add("@Charger", SqlDbType.Int, 10).Value = Charger;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }



        //charger
        public static DataTable Select_ChargeAGV_Need(string AGV_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_ChargeAGV_Need]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }
        public static DataTable Select_ChargeAGV_Start(string AGV_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_ChargeAGV_Start]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_ChargerInfo_ByChargerIP(string Charger_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_ChargerInfo_ByChargerIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Charger_IP", SqlDbType.VarChar, 50).Value = Charger_IP;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }
        public static int Update_ChargerInfo_Charger_AGV(string Charger_IP, string Charger_AGV)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_ChargerInfo_Charger_AGV]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Charger_IP", SqlDbType.VarChar, 50).Value = Charger_IP;
            comm.Parameters.Add("@Charger_AGV", SqlDbType.VarChar, 50).Value = Charger_AGV;
            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static DataTable Select_AGVInfo_ByIP(string AGV_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_AGVInfo_ByIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_AGVInfo_ByNO(string AGV_NO)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_AGVInfo_ByNO]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_NO", SqlDbType.VarChar, 50).Value = AGV_NO;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_AGVInfo_ByLocation(string AGV_Location)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_AGVInfo_ByLocation]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_Location", SqlDbType.VarChar, 50).Value = AGV_Location;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        //cross------
        public static DataTable Select_AGV_Order(string AGV_No)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_AGV_Order]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@OAGV", SqlDbType.VarChar, 50).Value = AGV_No;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_CrossInfo(int AGV_NO, string AGV_RFID, int AGV_FW, string OrderNo, string AGV_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_CrossInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_NO", SqlDbType.Int, 10).Value = AGV_NO;
            comm.Parameters.Add("@RFID", SqlDbType.VarChar, 50).Value = AGV_RFID;
            comm.Parameters.Add("@FW", SqlDbType.Int, 10).Value = AGV_FW;
            comm.Parameters.Add("@Cno", SqlDbType.VarChar, 50).Value = OrderNo;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }
        public static int Update_CrossInfo_Cno(string AGV_IP, string Cno)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_CrossInfo_Cno]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVIP", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@Cno", SqlDbType.VarChar, 50).Value = Cno;
            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }


        //-------end

        public static DataTable Select_Simulation_MapInfo()
        {
            SqlCommand comm = new SqlCommand("[PR_SELECT_MapInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable CALL_MESSAGE = null;
            try
            {
                //SQLServerDBController._defultConnectionString = conStrSim;
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch  
            {
            }
            return CALL_MESSAGE;
        }
        public static DataTable Select_TaskInfo_ByState(string TaskState)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_TaskInfo_ByState]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskState", SqlDbType.VarChar, 50).Value = TaskState;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable PR_Select_Station_ByStationLocation(string StationLocation)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_Station_ByStationLocation]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@StationLocationn", SqlDbType.VarChar, 50).Value = StationLocation;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }
        public static DataTable Select_TaskInfo_ByTaskContent(string TaskContent)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_TaskInfo_ByTaskContent]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskContent", SqlDbType.VarChar, 50).Value = TaskContent;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_TaskInfo_ByAGVIP(string AGVIP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_TaskInfo_ByAGVIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVIP", SqlDbType.VarChar, 50).Value = AGVIP;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_TaskInfo_ForShow()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_TaskInfo_ForShow]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        //TASK--------------------
        public static int Insert_TaskInfo(string TaskContent, string TaskAction, string TaskDefaultAGV, string TaskCreateRemark, string TaskPublisher, string TaskState, string TaskType)
        {
            SqlCommand comm = new SqlCommand("[PR_Insert_TaskInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskContent", SqlDbType.VarChar, 500).Value = TaskContent;
            comm.Parameters.Add("@TaskAction", SqlDbType.VarChar, 50).Value = TaskAction;
            comm.Parameters.Add("@TaskDefaultAGV", SqlDbType.VarChar, 50).Value = TaskDefaultAGV;
            comm.Parameters.Add("@TaskCreateRemark", SqlDbType.VarChar, 50).Value = TaskCreateRemark;
            comm.Parameters.Add("@TaskPublisher", SqlDbType.VarChar, 50).Value = TaskPublisher;
            comm.Parameters.Add("@TaskState", SqlDbType.VarChar, 50).Value = TaskState;
            comm.Parameters.Add("@TaskType", SqlDbType.VarChar, 50).Value = TaskType;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static int PR_Insert_TaskInfoInit(string TaskContent, string TaskState)
        {
            SqlCommand comm = new SqlCommand("[PR_Insert_TaskInfoInit]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskContent", SqlDbType.VarChar, 500).Value = TaskContent;
            comm.Parameters.Add("@TaskState", SqlDbType.VarChar, 50).Value = TaskState;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int PR_Insert_TaskInfoInit_AndType(string codeQ, string Nowkind, string ZhongLing)
        {
            SqlCommand comm = new SqlCommand(
                @"Insert into MES_KPWIPRUNCARD_R "
                + " (KPSN,PARTNO,QTY) "
                + " VALUES ('" + codeQ + "','" + Nowkind + "','" + ZhongLing + "'");
            comm.CommandType = CommandType.Text;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception e)
            {
                i = -1;
                LogHelper.SaveLog(e.ToString() + "\r\n", LogHelper.LogType.ErrorInfo, "录入失败");
            }
            return i;
        }

        public static int Update_AGVInfo_NeedCharger(string AGVIP, string NeedCharger)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AGVInfo_NeedCharger]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVIP", SqlDbType.VarChar, 50).Value = AGVIP;
            comm.Parameters.Add("@NeedCharger", SqlDbType.VarChar, 50).Value = NeedCharger;
            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static int Update_ChargerInfo_ChargerState(string Charger_IP, string Charger_State)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_ChargerInfo_ChargerState]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Charger_IP", SqlDbType.VarChar, 50).Value = Charger_IP;
            comm.Parameters.Add("@Charger_State", SqlDbType.VarChar, 50).Value = Charger_State;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static int Update_TaskAGVandHandleDateTime(int TaskID, string TaskHandleAGV, string TaskState)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_TaskAGVandHandleDateTime]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskID", SqlDbType.Int, 50).Value = TaskID;
            comm.Parameters.Add("@TaskHandleAGV", SqlDbType.VarChar, 50).Value = TaskHandleAGV;
            comm.Parameters.Add("@TaskState", SqlDbType.VarChar, 50).Value = TaskState;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int PR_Update_ElevatorOrder_ToTargetFloor_ByNo(int ElevatorOrder_ToTargetFloor, int ElevatorOrder_ID, int ElevatorOrder_AGVElevatorNO)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_ElevatorOrder_ToTargetFloor_ByNo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@ElevatorOrder_ToTargetFloor", SqlDbType.Int, 50).Value = ElevatorOrder_ToTargetFloor;
            comm.Parameters.Add("@ElevatorOrder_ID", SqlDbType.Int, 50).Value = ElevatorOrder_ID;
            comm.Parameters.Add("@ElevatorOrder_AGVElevatorNO", SqlDbType.Int, 50).Value = ElevatorOrder_ID;
            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int PR_Update_ElevatorOrder_AGV_ByNo(string AGV_IP, int ElevatorOrder_ID)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_ElevatorOrder_AGV_ByNo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@ElevatorOrder_AGV", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@ElevatorOrder_ID", SqlDbType.Int, 50).Value = ElevatorOrder_ID;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_TaskAGVandFinishDateTime(int TaskID, string TaskHandleAGV, string TaskState)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_TaskAGVandFinishDateTime]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskID", SqlDbType.Int, 50).Value = TaskID;
            comm.Parameters.Add("@TaskHandleAGV", SqlDbType.VarChar, 50).Value = TaskHandleAGV;
            comm.Parameters.Add("@TaskState", SqlDbType.VarChar, 50).Value = TaskState;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int PR_Update_Task_TaskState(int TaskID, string TaskState)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_Task_TaskState]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskID", SqlDbType.Int, 50).Value = TaskID;
            comm.Parameters.Add("@TaskState", SqlDbType.VarChar, 50).Value = TaskState;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int PR_Update_Task_TaskType(int TaskID, string TaskType)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_Task_TaskType]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskID", SqlDbType.Int, 50).Value = TaskID;
            comm.Parameters.Add("@TaskType", SqlDbType.VarChar, 50).Value = TaskType;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int PR_Update_TaskReserve2(int TaskID, string Reserve2)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_TaskReserve2]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskID", SqlDbType.Int, 50).Value = TaskID;
            comm.Parameters.Add("@Reserve2", SqlDbType.VarChar, 50).Value = Reserve2;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_TaskState_ManualFinished(int TaskID, string TaskState)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_TaskState_ManualFinished]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskID", SqlDbType.Int, 50).Value = TaskID;
            comm.Parameters.Add("@TaskState", SqlDbType.VarChar, 50).Value = TaskState;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_TaskState_ManualInit(int TaskID, string TaskState)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_TaskState_ManualInit]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskID", SqlDbType.Int, 50).Value = TaskID;
            comm.Parameters.Add("@TaskState", SqlDbType.VarChar, 50).Value = TaskState;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static int Delete_Task_ByID(int TaskID)
        {
            SqlCommand comm = new SqlCommand("[PR_Delete_Task_ByID]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskID", SqlDbType.Int, 10).Value = TaskID;
            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="TaskState"></param>
        /// <param name="AGV_IP"></param>
        /// <param name="TimeSpan_Second">时间间隔</param>
        /// <returns></returns>
        public static DataTable Select_TaskFinished(string TaskState, string AGV_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_TaskFinished]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskState", SqlDbType.VarChar, 50).Value = TaskState;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;


            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        //elevator
        public static DataTable Select_ElevatorInfo()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_ElevatorInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_ElevatorInfo_ByNo(int Sid)
        {
            SqlCommand comm = new SqlCommand("[Select_ElevatorInfo_ByNo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Sid", SqlDbType.Int, 10).Value = Sid;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_ElevatorOrder_ByNOIP(string ElevatorOrder_NO, string ElevatorOrder_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_ElevatorOrder_ByNOIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@ElevatorOrder_NO", SqlDbType.VarChar, 50).Value = ElevatorOrder_NO;
            comm.Parameters.Add("@ElevatorOrder_IP", SqlDbType.VarChar, 50).Value = ElevatorOrder_IP;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_ElevatorOrder_ByIP(string ElevatorOrder_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_ElevatorOrder_ByIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@ElevatorOrder_IP", SqlDbType.VarChar, 50).Value = ElevatorOrder_IP;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static int Update_ElevatorOrder_ByNOIP(string ElevatorOrder_NO, string ElevatorOrder_IP, int type, int louceng)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_ElevatorOrder_ByNOIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@ElevatorOrder_NO", SqlDbType.VarChar, 50).Value = ElevatorOrder_NO;
            comm.Parameters.Add("@ElevatorOrder_IP", SqlDbType.VarChar, 50).Value = ElevatorOrder_IP;
            comm.Parameters.Add("@type", SqlDbType.Int, 10).Value = type;
            comm.Parameters.Add("@louceng", SqlDbType.Int, 10).Value = louceng;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_ElevatorOrder_ByIP(string ElevatorOrder_IP, int type)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_ElevatorOrder_ByIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@ElevatorOrder_IP", SqlDbType.VarChar, 50).Value = ElevatorOrder_IP;
            comm.Parameters.Add("@type", SqlDbType.Int, 10).Value = type;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_ElevatorOrderNull_ByIP(string ElevatorOrder_IP, int type)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_ElevatorOrderNull_ByIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@ElevatorOrder_IP", SqlDbType.VarChar, 50).Value = ElevatorOrder_IP;
            comm.Parameters.Add("@type", SqlDbType.Int, 10).Value = type;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int PR_Update_ElevatorOrder_Action_ByIP(string ElevatorOrder_IP, int ElevatorOrder_Action)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_ElevatorOrder_Action_ByIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@ElevatorOrder_IP", SqlDbType.VarChar, 50).Value = ElevatorOrder_IP;
            comm.Parameters.Add("@ElevatorOrder_Action", SqlDbType.Int, 10).Value = ElevatorOrder_Action;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_State_LandMark_ByID(int TaskID, string ReadyInElevator, string ArriveFloor, string OutElevator)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_State_LandMark_ByID]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskID", SqlDbType.Int, 10).Value = TaskID;
            comm.Parameters.Add("@ReadyInElevator", SqlDbType.VarChar, 50).Value = ReadyInElevator;
            comm.Parameters.Add("@ArriveFloor", SqlDbType.VarChar, 50).Value = ArriveFloor;
            comm.Parameters.Add("@OutElevator", SqlDbType.VarChar, 50).Value = OutElevator;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_TaskState(int TaskID, string TaskState)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_TaskState]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@TaskID", SqlDbType.Int, 10).Value = TaskID;
            comm.Parameters.Add("@TaskState", SqlDbType.VarChar, 50).Value = TaskState;
            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch 
            {
                i = -1;
            }
            return i;
        }


        public static int Update_ElevatorInfo_Network(string Elevator_IP, int Elevator_Network)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_ElevatorInfo_Network]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Elevator_IP", SqlDbType.VarChar, 50).Value = Elevator_IP;
            comm.Parameters.Add("@Elevator_Network", SqlDbType.Int, 10).Value = Elevator_Network;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_CallBoxInfo_Network(string CallBox_IP, int CallBox_Network)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_CallBoxInfo_Network]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CallBox_IP", SqlDbType.VarChar, 50).Value = CallBox_IP;
            comm.Parameters.Add("@CallBox_Network", SqlDbType.Int, 10).Value = CallBox_Network;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_CallBoxLogic_DownTime(int CBLogic_CallBoxNO, int CBLogic_ButtonNO)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_CallBoxLogic_DownTime]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CBLogic_CallBoxNO", SqlDbType.Int, 10).Value = CBLogic_CallBoxNO;
            comm.Parameters.Add("@CBLogic_ButtonNO", SqlDbType.Int, 10).Value = CBLogic_ButtonNO;
            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_CallBoxLogic_ResetByNO(int CBLogic_CallBoxNO, int CBLogic_ButtonNO)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_CallBoxLogic_ResetByNO]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CBLogic_CallBoxNO", SqlDbType.Int, 10).Value = CBLogic_CallBoxNO;
            comm.Parameters.Add("@CBLogic_ButtonNO", SqlDbType.Int, 10).Value = CBLogic_ButtonNO;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }



        public static int Update_CallBoxLogic_CancelTime(int CBLogic_CallBoxNO, int CBLogic_ButtonNO)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_CallBoxLogic_CancelTime]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CBLogic_CallBoxNO", SqlDbType.Int, 10).Value = CBLogic_CallBoxNO;
            comm.Parameters.Add("@CBLogic_ButtonNO", SqlDbType.Int, 10).Value = CBLogic_ButtonNO;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_ElevatorInfo(string Elevator_IP, int Elevator_Network, int Elevator_DoorState, int Elevator_Floor)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_ElevatorInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Elevator_IP", SqlDbType.VarChar, 50).Value = Elevator_IP;
            comm.Parameters.Add("@Elevator_Network", SqlDbType.Int, 10).Value = Elevator_Network;
            comm.Parameters.Add("@Elevator_DoorState", SqlDbType.Int, 10).Value = Elevator_DoorState;
            comm.Parameters.Add("@Elevator_Floor", SqlDbType.Int, 10).Value = Elevator_Floor;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Insert_LogInfo(string Log_Type, string Log_Content, string Log_DateTime, string Log_Publisher, int Log_SaveType)
        {
            SqlCommand comm = new SqlCommand("[PR_Insert_LogInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Log_Type", SqlDbType.VarChar, 50).Value = Log_Type;
            comm.Parameters.Add("@Log_Content", SqlDbType.VarChar, 1000).Value = Log_Content;
            comm.Parameters.Add("@Log_DateTime", SqlDbType.VarChar, 50).Value = Log_DateTime;
            comm.Parameters.Add("@Log_Publisher", SqlDbType.VarChar, 50).Value = Log_Publisher;
            comm.Parameters.Add("@Log_SaveType", SqlDbType.Int, 10).Value = Log_SaveType;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static DataTable Select_CallBoxLogic()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_CallBoxLogic]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_CallBoxLogicIsDown()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_CallBoxLogicIsDown]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_PadTask()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_PadTask]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_CallBoxLogic_ForShow()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_CallBoxLogic_ForShow]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }
        public static DataTable Select_CacheInfo(string State)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_CacheInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@State", SqlDbType.VarChar, 50).Value = State;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }
        public static DataTable Select_CallBoxInfo()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_CallBoxInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }
        public static DataTable SELECT_CROSS_CAC(string AGV_RFID, string AGVNo)
        {
            SqlCommand comm = new SqlCommand("PR_SELECT_CROSS_cac");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable CALL_MESSAGE = null;
            comm.Parameters.Add("@RFID", SqlDbType.VarChar, 50).Value = AGV_RFID;
            comm.Parameters.Add("@AGV_NO", SqlDbType.VarChar, 50).Value = AGVNo;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
                CALL_MESSAGE = null;
            }
            return CALL_MESSAGE;
        }
        public static DataTable Select_AGVAndElevator_Order(string AGV_No)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_AGVAndElevator_Order]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@OAGV", SqlDbType.VarChar, 50).Value = AGV_No;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_TaskInfo_ByPoint(string Point)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_TaskInfo_ByPoint]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Point", SqlDbType.VarChar, 50).Value = Point;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_tb_ElevatorRuler_MainLineNO(string LineNo, string AGV_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_tb_ElevatorRuler_MainLineNO]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@MAINLINENO", SqlDbType.VarChar, 50).Value = LineNo;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_Elevator_ByIP(string IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_Elevator_ByIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Sip", SqlDbType.VarChar, 50).Value = IP;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }


        public static int Update_Elevator_AGVNO(string ELE_IP, int AGV_No)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_Elevator_AGVNO]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@SIP", SqlDbType.VarChar, 50).Value = ELE_IP;
            comm.Parameters.Add("@SAGVNO", SqlDbType.Int, 10).Value = AGV_No;
            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }


        /// <summary>
        /// 更新AGV当前交互设备任务号
        /// </summary>
        /// <param name="AGV_IP"></param>
        /// <param name="AGV_LineNo"></param>
        /// <returns></returns>
        public static int Update_AGVInfo_From(string AGV_IP, string AGV_LineNo)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AGVInfo_From]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVIP", SqlDbType.VarChar, 50).Value = AGV_IP;
            comm.Parameters.Add("@AGVFROM", SqlDbType.VarChar, 50).Value = AGV_LineNo;
            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_CacheInfo_State(string no, string state)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_CacheInfo_State]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@No", SqlDbType.VarChar, 50).Value = no;
            comm.Parameters.Add("@State", SqlDbType.VarChar, 50).Value = state;
            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_AutoDoorInfo_Order(string RFID, int Direction, string AutoDoor_IP, string AGV_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AutoDoorInfo_Order]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@RFID", SqlDbType.VarChar, 50).Value = RFID;
            comm.Parameters.Add("@FW", SqlDbType.Int, 10).Value = Direction;
            comm.Parameters.Add("@D_IP", SqlDbType.VarChar, 50).Value = AutoDoor_IP;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_AutoDoorInfo_Network(string AutoDoor_IP, int AutoDoor_Network)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AutoDoorInfo_Network]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AutoDoor_IP", SqlDbType.VarChar, 50).Value = AutoDoor_IP;
            comm.Parameters.Add("@AutoDoor_Network", SqlDbType.Int, 10).Value = AutoDoor_Network;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static int Update_AutoInfo(string AutoDoor_IP, int AutoDoor_Network, int AutoDoor_DoorState, int storage)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_AutoInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AutoDoor_IP", SqlDbType.VarChar, 50).Value = AutoDoor_IP;
            comm.Parameters.Add("@AutoDoor_Network", SqlDbType.Int, 10).Value = AutoDoor_Network;
            comm.Parameters.Add("@AutoDoor_DoorState", SqlDbType.Int, 10).Value = AutoDoor_DoorState;
            comm.Parameters.Add("@Storage", SqlDbType.Int, 10).Value = storage;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static DataTable Select_AutoDoor_ByIP(string AutoDoor_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_AutoDoor_ByIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AutoDoor_IP", SqlDbType.VarChar, 50).Value = AutoDoor_IP;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }
        public static DataTable Select_AutoDoor()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_AutoDoor]");
            comm.CommandType = CommandType.StoredProcedure;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_AutoDoorAndAGV_ByIP(string AutoDoor_IP, string AGV_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_AutoDoorAndAGV_ByIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AutoDoor_IP", SqlDbType.VarChar, 50).Value = AutoDoor_IP;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static int Update_CallBoxLogic_ToTask(int CBLogic_CallBoxNO, int CBLogic_ButtonNO, string serial)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_CallBoxLogic_ToTask]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CBLogic_CallBoxNO", SqlDbType.Int, 10).Value = CBLogic_CallBoxNO;
            comm.Parameters.Add("@CBLogic_ButtonNO", SqlDbType.Int, 10).Value = CBLogic_ButtonNO;
            comm.Parameters.Add("@serial", SqlDbType.VarChar, 50).Value = serial;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static DataTable Select_LoudspeakerInfo()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_LoudspeakerInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }
        public static DataTable Select_LoudspeakerInfo_S()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_LoudspeakerInfo_S]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }


        public static DataTable Select_LoudspeakerInfo_ByIP(string Loudspeaker_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_LoudspeakerInfo_ByIP]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Loudspeaker_IP", SqlDbType.VarChar, 50).Value = Loudspeaker_IP;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static int Update_LoudspeakerInfo(string Loudspeaker_IP, int Loudspeaker_Network, string Loudspeaker_WorkingState)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_LoudspeakerInfo]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Loudspeaker_IP", SqlDbType.VarChar, 50).Value = Loudspeaker_IP;
            comm.Parameters.Add("@Loudspeaker_Network", SqlDbType.Int, 10).Value = Loudspeaker_Network;
            comm.Parameters.Add("@Loudspeaker_WorkingState", SqlDbType.Int, 10).Value = Loudspeaker_WorkingState;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_LoudspeakerInfo_Network(string Loudspeaker_IP, int Loudspeaker_Network)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_LoudspeakerInfo_Network]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Loudspeaker_IP", SqlDbType.VarChar, 50).Value = Loudspeaker_IP;
            comm.Parameters.Add("@Loudspeaker_Network", SqlDbType.Int, 10).Value = Loudspeaker_Network;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_LoudspeakerInfo_Control(string Loudspeaker_IP, string Loudspeaker_Control)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_LoudspeakerInfo_Control]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Loudspeaker_IP", SqlDbType.VarChar, 50).Value = Loudspeaker_IP;
            comm.Parameters.Add("@Loudspeaker_Control", SqlDbType.VarChar, 50).Value = Loudspeaker_Control;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_AutoDoor_Step(string AutoDoor_IP, int AutoDoor_Step)
        {
            SqlCommand comm = new SqlCommand("[Update_AutoDoor_Step]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AutoDoor_IP", SqlDbType.VarChar, 50).Value = AutoDoor_IP;
            comm.Parameters.Add("@AutoDoor_Step", SqlDbType.Int, 10).Value = AutoDoor_Step;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_AutoDoorAction(string AutoDoor_IP, int Action)
        {
            SqlCommand comm = new SqlCommand("[Update_AutoDoorAction]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AutoDoor_IP", SqlDbType.VarChar, 50).Value = AutoDoor_IP;
            comm.Parameters.Add("@Action", SqlDbType.Int, 10).Value = Action;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }


        public static DataTable Select_StorageLocation()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_StorageLocation]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }

        public static DataTable Select_CallBoxLogic_ByTwoNO(int CBLogic_CallBoxNO, int CBLogic_ButtonNO)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_CallBoxLogic_ByTwoNO]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CBLogic_CallBoxNO", SqlDbType.Int, 10).Value = CBLogic_CallBoxNO;
            comm.Parameters.Add("@CBLogic_ButtonNO", SqlDbType.Int, 10).Value = CBLogic_ButtonNO;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_TaskInfo_BySerial(string Serial)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_TaskInfo_BySerial]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@Serial", SqlDbType.VarChar, 50).Value = Serial;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }
        public static int Update_CallBoxLogic_Reset(string serial)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_CallBoxLogic_Reset]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@serial", SqlDbType.VarChar, 50).Value = serial;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_PLCStateTask(string Name)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_PLCStateTask]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@PLCName", SqlDbType.VarChar, 50).Value = Name;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static DataTable Select_AGVDoingTask(string AGV_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_AGVDoingTask]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }


        public static int Update_StorageLocation_ByNO(string CallBoxNO, string ButtonNo, string NowState)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_StorageLocation_ByNO]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CallBoxNO", SqlDbType.VarChar, 50).Value = CallBoxNO;
            comm.Parameters.Add("@ButtonNo", SqlDbType.VarChar, 50).Value = ButtonNo;
            comm.Parameters.Add("@NowState", SqlDbType.VarChar, 50).Value = NowState;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_StorageLocation_ByRFID(string RFID, string NowState)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_StorageLocation_ByRFID]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@RFID", SqlDbType.VarChar, 50).Value = RFID;
            comm.Parameters.Add("@NowState", SqlDbType.VarChar, 50).Value = NowState;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }


        public static DataTable Select_TaskInfo_ByAGV_IP_ForCharger(string AGV_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_TaskInfo_ByAGV_IP_ForCharger]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static DataTable Select_Plan_ByCX(string CX)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_Plan_ByCX]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CX", SqlDbType.VarChar, 50).Value = CX;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

        public static int Update_PlanState_ByCX(string CX)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_PlanState_ByCX]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CX", SqlDbType.VarChar, 50).Value = CX;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_PlanState_ByCX_END(string AGVNO)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_PlanState_ByCX_END]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVNO", SqlDbType.VarChar, 50).Value = AGVNO;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static int Update_CXCallInfo_ByCX_END(string AGVNO)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_CXCallInfo_ByCX_END]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVNO", SqlDbType.VarChar, 50).Value = AGVNO;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static int Update_CXCallInfo_FinishDate(string AGVNO)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_CXCallInfo_FinishDate]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGVNO", SqlDbType.VarChar, 50).Value = AGVNO;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_PlanAGV_ByCallBox(string CallBoxNO, string ButtonNO, string AGVNO)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_PlanAGV_ByCallBox]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CallBoxNO", SqlDbType.VarChar, 50).Value = CallBoxNO;
            comm.Parameters.Add("@ButtonNO", SqlDbType.VarChar, 50).Value = ButtonNO;
            comm.Parameters.Add("@AGVNO", SqlDbType.VarChar, 50).Value = AGVNO;


            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }
        public static int Update_CXCallInfo_ByCallBox(string CallBoxNO, string ButtonNO, string AGVNO)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_CXCallInfo_ByCallBox]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CallBoxNO", SqlDbType.VarChar, 50).Value = CallBoxNO;
            comm.Parameters.Add("@ButtonNO", SqlDbType.VarChar, 50).Value = ButtonNO;
            comm.Parameters.Add("@AGVNO", SqlDbType.VarChar, 50).Value = AGVNO;


            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        /// <summary>
        /// SET Loudspeaker_Control=@control WHERE Loudspeaker_Location=@CallBox and Loudspeaker_Type=@voiceType
        /// </summary>
        /// <param name="CallBox">喇叭编号-对应楼层号表示</param>
        /// <param name="control">响/不响</param>
        /// <param name="voiceType">语音类型：1缺料，2缺料车，3缺空车位</param>
        /// <returns></returns>
        public static int Update_Loudspeaker_Control_ByCallBox(string CallBox, string control, string voiceType)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_Loudspeaker_Control_ByCallBox]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CallBox", SqlDbType.VarChar, 50).Value = CallBox;
            comm.Parameters.Add("@control", SqlDbType.VarChar, 50).Value = control;
            comm.Parameters.Add("@voiceType", SqlDbType.VarChar, 50).Value = voiceType;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }


        public static int Update_Loudspeaker_Control_ByVoiceAndType(string control, string voice, string AGVAreaType)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_Loudspeaker_Control_ByVoiceAndType]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@control", SqlDbType.VarChar, 50).Value = control;
            comm.Parameters.Add("@voice", SqlDbType.VarChar, 50).Value = voice;
            comm.Parameters.Add("@AGVAreaType", SqlDbType.VarChar, 50).Value = AGVAreaType;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static int Update_Loudspeaker_Control_ByCallBox_Reset(string CallBox, string control, string voice)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_Loudspeaker_Control_ByCallBox_Reset]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@CallBox", SqlDbType.VarChar, 50).Value = CallBox;
            comm.Parameters.Add("@control", SqlDbType.VarChar, 50).Value = control;
            comm.Parameters.Add("@voice", SqlDbType.VarChar, 50).Value = voice;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static DataTable Select_Storage_ByStateAndRemark(string StorageLocation_State, string StorageLocation_Remark)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_Storage_ByStateAndRemark]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@StorageLocation_State", SqlDbType.VarChar, 50).Value = StorageLocation_State;
            comm.Parameters.Add("@StorageLocation_Remark", SqlDbType.VarChar, 50).Value = StorageLocation_Remark;

            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }


        public static int Update_StorageLocation_ByNO_Manual(string StorageLocation_NO, string NowState)
        {
            SqlCommand comm = new SqlCommand("[PR_Update_StorageLocation_ByNO_Manual]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@StorageLocation_NO", SqlDbType.VarChar, 50).Value = StorageLocation_NO;
            comm.Parameters.Add("@NowState", SqlDbType.VarChar, 50).Value = NowState;

            int i = -1;
            try
            {
                i = SQLServerDBController.ExecuteNonQuery(comm);
            }
            catch (Exception)
            {
                i = -1;
            }
            return i;
        }

        public static DataTable Select_TaskInfo_Publisher_ByIPState(string AGV_IP)
        {
            SqlCommand comm = new SqlCommand("[PR_Select_TaskInfo_Publisher_ByIPState]");
            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@AGV_IP", SqlDbType.VarChar, 50).Value = AGV_IP;

            DataTable res = null;
            try
            {
                res = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return res;
        }

        public static DataTable Select_CXCallInfo_NotGo()
        {
            SqlCommand comm = new SqlCommand("[PR_Select_CXCallInfo_NotGo]");
            comm.CommandType = CommandType.StoredProcedure;
            DataTable CALL_MESSAGE = null;
            try
            {
                CALL_MESSAGE = SQLServerDBController.ExecuteQuery(comm).Tables[0];
            }
            catch (Exception)
            {
            }
            return CALL_MESSAGE;
        }

    }
}
